/**
 * json配置举例，更多配置请看 IConfigSchema
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { RadioGroup } from 'tdesign-vue-next';
import { has, IConfigSchema, LgBizSelect, LgBizSelectProps } from '@/soar';
import tenantApi, { basePath as tenantBasePath } from '@/pages/system/tenant/manage/api';
import GetUser from '@/pages/system/tenant/user/GetUser.vue';
import { basePath } from './api';
import { MenuComponent } from '@/types/interface';

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'tenantId',
    label: '租户',
    dataType: 'string',
    predicate: () => has.tenant(0),
    table: {
      colKey: 'tenantName',
    },
    search: {
      component: LgBizSelect,
      componentProps: {
        placeholder: '请选择${label}',
        data: tenantApi.query,
      } as LgBizSelectProps,
    },
    form: {
      disabled({ isUpdate }) {
        return isUpdate;
      },
      component: LgBizSelect,
      componentProps: {
        placeholder: '请选择${label}',
        data: tenantApi.query,
      } as LgBizSelectProps,
    },
  },
  {
    field: 'userId',
    label: '账号',
    dataType: 'string',
    table: {
      colKey: 'username',
    },
    search: false,
    form: {
      field: 'username',
      component: GetUser,
    },
  },
  {
    field: 'realname',
    label: '姓名',
    dataType: 'string',
  },
  {
    field: 'status',
    label: '状态',
    dataType: 'dict',
    params: 'TenantUserStatusEnum',
    form: {
      componentProps: {
        component: RadioGroup,
      },
    },
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '租户用户',
    component: () => import('./List.vue'),
    sort: 20,
    keepalive: true,
    icon: 'usergroup',
    permits: [`GET${basePath}/query`, `GET${tenantBasePath}/query`],
    elements: [
      { title: '新增', code: 'create', permits: [`POST${basePath}/create`] },
      { title: '更新', code: 'update', permits: [`POST${basePath}/update`, `GET${basePath}/detail`] },
      { title: '删除', code: 'remove', permits: [`POST${basePath}/remove`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
      { title: '导入', code: 'import', permits: [`POST${basePath}/import`] },
      { title: '导出', code: 'export', permits: [`GET${basePath}/export`] },
    ],
  },
];
